package site.luoji.session;

import org.dom4j.DocumentException;
import site.luoji.parseing.XMLConfigBuilder;
import site.luoji.session.defaults.DefaultSqlSessionFactory;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * @Description: 解析配置文件、并构建SqlSessionFactory
 * @Author jie.luo
 * @Create: 2020-04-28 11:14
 **/
public class SqlSessionFactoryBuilder {

    /**
     * 构建 SqlSessionFactory
     *
     * @param inputStream 配置文件字节码
     * @return SqlSessionFactory
     */
    public SqlSessionFactory build(InputStream inputStream) throws PropertyVetoException, DocumentException {

        // 1.解析配置文件
        XMLConfigBuilder configBuilder = new XMLConfigBuilder();
        Configuration configuration = configBuilder.parse(inputStream);

        // 2.构建 SqlSessionFactory
        SqlSessionFactory sessionFactory = new DefaultSqlSessionFactory(configuration);
        return sessionFactory;
    }

}
